//
//  PraiseShow.m
//  SDDataTest
//
//  Created by sodao on 12-9-19.
//  Copyright (c) 2012年 sodao. All rights reserved.
//

#import "PraiseShow.h"
#import "Dynamic.h"
#import "Person.h"
#import "Show.h"

@implementation PraiseShow
@synthesize shows;
@synthesize owner;
@synthesize prasieCount;
@synthesize dynamic;
- (void)encodeWithCoder:(NSCoder *)aCoder{
    [aCoder encodeObject:self.dynamic forKey:kDynamic_EncodeKey];
    [aCoder encodeObject:owner forKey:kOwner_EncodeKey];
    [aCoder encodeObject:shows forKey:kShows_EncodeKey];
    [aCoder encodeInt:self.prasieCount forKey:kPraiseCount_EncodeKey];
    
}
- (id)initWithCoder:(NSCoder *)decoder {
    if (self = [super init]) {
        self.dynamic = [decoder decodeObjectForKey:kDynamic_EncodeKey];
        self.owner = [decoder decodeObjectForKey:kOwner_EncodeKey];
        self.shows = [decoder decodeObjectForKey:kShows_EncodeKey];
        self.prasieCount = [decoder decodeIntForKey:kPraiseCount_EncodeKey];
    }
    return self;
}
-(id)init{
    if (self = [super init]) {
        shows = [[NSMutableArray alloc] init];
    }
    return self;
}
-(id)initwithDictionary:(NSDictionary *)dictionary{
    if (self= [super initWithDictionary:dictionary]) {
        self.dynamic = [[Dynamic alloc] initWithDictionary:dictionary];
        NSDictionary* dynamicinfo = (NSDictionary*)[dictionary objectForKey:@"dynamicinfo"];
        Person *temp = [[Person alloc] initWithDictionary:dynamicinfo];
        self.owner=temp;
        NSArray* array = [dynamicinfo objectForKey:@"shows"];
        for (NSDictionary* d in array) {
            Show* show = [[Show alloc] initWithDictionary:d];
            [self.shows addObject:show];
            [show release];
        }
        self.prasieCount = [[dynamicinfo objectForKey:@"count"] intValue];
    }
    return self;
}
-(void)dealloc{
    [super dealloc];
    [self.shows removeAllObjects];
    [self.shows release];
    [self.owner release];
    [self.dynamic release];
}
@end
